package com.wingsboat;

/**
 * @author wangzhong
 * @description: 约瑟夫问题
 * @date 2024/7/23 16:19
 */
public class Test20 {
    public static void main(String[] args) {
        int[] arr = {3,1,2,4};
        int m = 7;
        int size = 0;
        int count = 0;
        int index =0;
        int[] result = new int[arr.length];
        while(size<arr.length){
            if(arr[index%arr.length]!=-1){
                count+=1;
            }
            if(m==count){
                result[size] = arr[index%arr.length];
                m = arr[index%arr.length];
                size+=1;
                arr[index%arr.length] = -1;
                count = 0;
            }
            index++;
        }
        for (int i : result) {
            System.out.println(i);
        }

    }
}

class circleNode{
    public Node20 header;
    public Node20 tail;

    public int size;

    public void addNode(int num){
        Node20 node = new Node20();
        node.num = num;
        if(size==0){
            header = node;
        }else{
            tail.next = node;
        }
        tail = node;
        tail.next = header;
        size++;
    }

    public void remove(Node20 node){

    }

}

class Node20{
    public int num;
    public Node20 next;
}
